//------------------------------------------------------------
// Global Variables
var DEBUG_FLAG = true;
var ghtPage = null;
var ghtNav = null;
//--------------------------------------------------------------
// Logging utility
function $$log(txt) {
	if(DEBUG_FLAG)
		console.log(txt);
}

//--------------------------------------------------------------
// Travelocity - don't pack, just go!
function $$GO(url) {
	window.location.href = url;
}

//--------------------------------------------------------------
// Application Classes
//------------------------------------------------------------

/**
 * Base class for all GHT pages.
 * 
 * Extended and constructed in each of the 
 * 'Context' scripts to provide the services 
 * represented by the context and usually 
 * managed via the Context Menu bar ('connav').
 */
var GHTPage = new Class ({
	name: "None",
	gif: null,
	
	/** constructor */
	initialize: function(pgName) {
		// set up internals
		this.name = pgName;
		setTimeout("ghtNav = new NavOpts(ghtPage.name);",1);
		
		if (this.name == "Home" || this.name == "About") {
            
        } else {
            //load vendors  
        }
	},
	
	/**
	 * Display Alert Message
	 */
	alert: function(msg) {
		this.flashMessage(msg).set('style','color: #f00');
	},
	
	/**
	 * Display Standard Message
	 */
	flashMessage: function(msg) {
		return $('flashMsg').set('text',msg);
	},
	
	/**
	 * Display Standard Message
	 */
	clearMessage: function() {
		return $('flashMsg').set('text','');
	},
	
	loadContent: function(page) {
		$('content').load(page);
	}
	
});


/**
 * Site Navigation Management Class
 * 
 * Initialized and constructed in 
 * GHTPage constructor and can be
 * accessed globally by ghtNav 
 * global variable.
 */
var NavOpts = new Class ({
	
	sorryMessage: 'Sorry, This feature has not been released.',
	
	/**
	 * This property defines the application's
	 * multi-tiered navigation system structure.
	 */
	navigation: {
		
		 'Home': [{ href:'/GHT?action=Index',title:'Front Page'},
		         {
					
		         }],
         
		 'About': [{ href:'/GHT?action=About',title:'About Us'},
 		         {
			 
 		         }],
        
 		 'Products': [{ href:'/GHT?action=products.Index',title:'Products'},
 		         {
			 
 		         }],
        
         'Videos': [{ href:'/GHT?action=videos.Index',title:'Videos'},
                 {
             
                 }],
                 
         'Contact': [{ href:'/GHT?action=Contact',title:'Contact'},
                 {
             
                 }]
	},
	
	/** Constructor */
	initialize: function() {
		// get our name from page
		this.name = ghtPage.name;
		
		subs = this.build(this.name,'topnav',this.navigation);
		if(subs)
			this.build('-','connav',subs);
	},
	
	
	/**
	 * Load page results into div 
	 * (aka AJAX)
	 */
	load: function(href,div) {
		$(div).load(href);
	},
	
	/**
	 * Build a navigations row for 
	 * current page
	 */
	build: function (pg, divnm, opts) {
		var rv = null;		
		
		// open target cell
		td = $$('td.'+divnm);
		td.set("style","height:15px");
		
		// get target div
		dv = $$('#'+divnm)[0];
		dv.set("style: text-align:center");

		// create menu options
		for(opt in opts){
			// prepare element 
			a = null;
			
			// check for current page
			if (opt == pg) {
				// set return if this one has children
				if (opts[opt].length > 1) 
					rv = opts[opt][1];
				
				// set for active opt
				a = new Element('span').set('text',opt).addClass('activeNav');				
			}
			else 
				// create the menu option link
				a = new Element('a').setProperties(opts[opt][0]).set('text',opt).addClass((pg == '-') ? "activeNav" : "navlink");
			
			// and add to the div
			a.inject(dv);
		}
		// add to div block
		dv.set('class','display: block');

		// all done, return context menu (if any)
		return rv
	}
	
});

